package cn.com.taurus.controller.finance;

import cn.com.taurus.entity.DealMessage;
import cn.com.taurus.entity.Fund;
import cn.com.taurus.impl.DealMessageImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
public class FinanceController {
    @Autowired
    DealMessageImpl dealMessageImpl;

    @RequestMapping("/buyApplication.do")
    public ModelAndView buyApplication(String fId,Double afterRate,Integer caId,Double applyBuy){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //根据参数创建交易申请对象  第四个参数计算日期，第五个计算手续费
        DealMessage dealMessage = new DealMessage
                (0,caId,fId,applyBuy,simpleDateFormat.format(date.getTime()),afterRate * applyBuy);
        ModelAndView modelAndView;
        if (dealMessageImpl.buyApplication(dealMessage) > 0){
            modelAndView = new ModelAndView("");
        }else {
            modelAndView = new ModelAndView("");
        }
        return modelAndView;
    }
}
